import Cookie from 'js-cookie'
import Mock from 'mockjs'
import { getLogin } from "../api";

const state ={
    token:''
};
const mutations = {
    setToken(state, val) {
        state.token = val
        Cookie.set('token', val)
    },
    clearToken(state) {
        state.token = ''
        Cookie.remove('token')
    },
    getToken(state) {
        state.token = state.token|| Cookie.get('token')
    },
    
};
const actions = {
    async login({commit},val) {
        
        let result=await getLogin(val)
        if (result.data == 200) {
            const token = Mock.Random.guid()
            commit('setToken', token)    
        }

    
    }
};
const getters = {};

export default{
    state,
    mutations,
    actions,
    getters
}